#include "testcontentmenu.h"
#include <qmenu.h>
#include <qaction.h>
#include <qpoint.h>

testcontentmenu::testcontentmenu(QWidget *parent)
    : QMainWindow(parent)
    , m_content_menu{}
{
    ui.setupUi(this);
    OnInitDialog();
}


void testcontentmenu::OnInitDialog()
{
    if(nullptr == m_content_menu)
        m_content_menu = new QMenu();
    Q_ASSERT(m_content_menu);
    m_content_menu->setWindowFlags(m_content_menu->windowFlags() | Qt::FramelessWindowHint);

    connect(ui.toolButton_content, &QToolButton::clicked, [=]() {
        QPoint _pos{ ui.toolButton_content->pos() };
        _pos.setX(_pos.x() + ui.toolButton_content->width());
        _pos.setY(_pos.y() - ui.toolButton_content->height());
        m_content_menu->exec(mapToGlobal(_pos));
});

    auto _action1 = new QAction("fuck1");
    Q_ASSERT(_action1);
    m_content_menu->addAction(_action1);
    auto _action2 = new QAction("fuck2");
    m_content_menu->addAction(_action2);
    auto _action3 = new QAction("fuck3");
    m_content_menu->addAction(_action3);
    ui.toolButton_content->setMenu(m_content_menu);
    ui.toolButton_content->setStyleSheet("QToolButton::menu-indicator{image:none;}");//hide menu down arrow
}
